﻿package components 
{
	import flash.events.*;
	import flash.utils.*;
	
	/**
	 * 单例
	 * @author imi
	 */
	public class Singleton extends EventDispatcher
	{
		
		private static var root:Object;

        public function Singleton()
        {
            var name:String;
            if (root == null)  root = new Object();
            name = getQualifiedClassName(this);
            if (root[name] != null) return;
            root[name] = this;
            return;
        }
		
        public function dispose():void
        {
            var name:String;
            name = getQualifiedClassName(this);
            root[name] = null;
            return;
        }
		
        public static function getInstance(param1:Class):Object
        {
            var name:String;
            if (root == null) root = new Object();
            name = getQualifiedClassName(param1);
			if (root[name] == null) root[name] = new param1();	
            return root[name];
        }
	}
}